<template>
    <div class="record">
        <RiskTableP
            ref="recordTable"
            :tableConfig="tableConfig"
            :tableData="tableData"
            :column="tableColumns"
            :paging="paging"
            :searchParams="searchParams"
            v-loading="tableLoading"
            @page-change="getTableData"
            class="risk-table"
        >
        </RiskTableP>
        <div class="detail-div">
            <!-- <h3>详情</h3> -->
            <!-- <ComparionRecord :checkedRows="checkedRows" :title="$attrs.title" :type="type + '-record'" :keyName="type + 'Code'"></ComparionRecord> -->
        </div>
    </div>
</template>
<script lang="ts">
import { Component, Prop } from 'vue-property-decorator';
import { mixins } from 'vue-class-component';
import RiskEmitter from '@/common/mixis/risk-emitter.vue';
import RiskTableP from '@/common/components/risk-table-plus.vue';

import DictionConstUtil from '@/utils/diction-const-util';
import { ColumnVO, PageVO, TableConfigVO } from '@/common/vo';
import Dict from '../../dict/index';
import API from '../../api';
import { sourceManageRecordDTO } from '../../vo';

@Component({
    name: 'SourceManageRecord',
    components: {
        RiskTableP,
    },
})
export default class SourceManageRecord extends mixins(RiskEmitter) {
    @Prop() code: any;
    Dict = new Dict();
    tableConfig: TableConfigVO = {
        rowKey: 'operationNo_',
    };
    searchParams: sourceManageRecordDTO = {
        operationNo: '',
        operationType_: '',
        changeType_: '',
        sourceType_: '',
        sourceGroupType_: '',
        sourceCode_: '',
        sourceName_: '',
        sourceVersion_: '',
        sourceSuitableFund_: '',
        sourceFile_: '',
        sourceStatus_: '',
        sourcePublishDate_: '',
        sourceEffecDate_: '',
        sourceRemark_: '',
        operator_: '',
        operationTime_: '',
    };
    tableColumns: ColumnVO[] = [
        { field: 'operationNo', title: '操作序号', sortable: true, minWidth: '120px', filterType: 'search', filters: [{ data: '' }] },
        { field: 'operationType_', title: '操作类型', sortable: true, minWidth: '120px', filterType: 'funnel', filters: [] },
        {
            field: 'changeType_',
            title: '变动方式',
            minWidth: '120px',
            sortable: true,
            filterType: 'funnel',
            filters: [],
        },
        {
            field: 'sourceType_',
            title: '来源类型',
            minWidth: '120px',
            sortable: true,
            filterType: 'funnel',
            filters: [],
        },
        {
            field: 'sourceGroupType_',
            title: '来源分组',
            minWidth: '120px',
            sortable: true,
            filterType: 'search',
            filters: [{ data: '' }],
        },
        {
            field: 'sourceCode_',
            title: '来源编号',
            minWidth: '120px',
            sortable: true,
            filterType: 'search',
            filters: [{ data: '' }],
        },
        {
            field: 'sourceName_',
            title: '来源名称',
            minWidth: '140px',
            sortable: true,
            filterType: 'search',
            filters: [{ data: '' }],
        },
        {
            field: 'sourceVersion_',
            title: '来源版本号',
            minWidth: '120px',
            sortable: true,
            filterType: 'search',
            filters: [{ data: '' }],
        },
        {
            field: 'sourceSuitableFund_',
            title: '来源适用产品',
            minWidth: '160px',
            sortable: true,
            filterType: 'search',
            filters: [{ data: '' }],
        },
        {
            field: 'sourceFile_',
            title: '来源附件',
            minWidth: '180px',
            sortable: true,
            filterType: 'search',
            filters: [{ data: '' }],
        },
        {
            field: 'sourceStatus_',
            title: '来源状态',
            minWidth: '120px',
            sortable: true,
            filterType: 'funnel',
            filters: DictionConstUtil.PojoToList3(this.Dict.sourceStatusPojo),
            render: value => this.Dict.sourceStatusPojo[value],
            style: value => {
                return {
                    color: {
                        '0': 'red',
                        '1': 'green',
                    }[value],
                };
            },
        },
        {
            field: 'sourcePublishDate_',
            title: '来源发布/签署日期',
            minWidth: '180px',
            sortable: true,
        },
        {
            field: 'sourceEffecDate_',
            title: '来源生效日期',
            minWidth: '160px',
            sortable: true,
        },
        {
            field: 'sourceRemark_',
            title: '来源备注',
            minWidth: '160px',
            sortable: true,
            filterType: 'search',
            filters: [{ data: '' }],
        },
        {
            field: 'operator_',
            title: '操作人',
            minWidth: '120px',

            sortable: true,
            filterType: 'search',
            filters: [{ data: '' }],
        },
        {
            field: 'operationTime_',
            title: '操作时间',
            minWidth: '160px',
            sortable: true,
        },
    ];
    tableData: sourceManageRecordDTO[] = [
        {
            operationNo: '1',
            operationType_: '修改来源',
            changeType_: 'YH修改',
            sourceType_: '法律法规',
            sourceGroupType_: '证监会',
            sourceCode_: 'LY047',
            sourceName_: '中国证券登记结算指引',
            sourceVersion_: '2023版',
            sourceSuitableFund_: '公募-股票基金',
            sourceFile_: '中国证券登记结算指引.docx',
            sourceStatus_: '1',
            sourcePublishDate_: '2023-09-12',
            sourceEffecDate_: '2023-09-13',
            sourceRemark_: '修订',
            operator_: 'testuser1',
            operationTime_: '2021-08-20 12:00:02',
        },
    ];
    tableLoading: boolean = false;

    checkedRows: any[] = []; // 双击项所需数据
    paging: PageVO = {
        total: 0,
        currentPage: 1,
        pageSize: 10,
    };

    mounted() {
        this.getTableData();
    }
    /**
     *表格数据
     */
    getTableData($event?: any) {
        // if ($event && $event.type == 'sort') {
        //     this.searchParams.sort = {
        //         field: $event['sortField'],
        //         order: $event['order'],
        //     };
        // }

        let requestName = API.SourceUpdateRecordList;
        let requestData = {
            ...this.searchParams,
            paging: this.paging,
        };
        requestName(requestData).then((res: any) => {
            this.tableData = res?.list || [];
            this.paging.total = res?.total || 0;
        });
    }

    // 查看比对记录
    lookInfo(row, $rowIndex) {
        console.log(row, $rowIndex, '$event');
        this.checkedRows = [row];
    }
}
</script>
<style lang="scss" scoped>
.record {
    color: #222;
    height: 100%;
    .risk-table {
        height: calc(70vh - 250px) !important;
    }
}
.detail-div {
    height: 200px;
    overflow: auto;
    border-top: 1px solid #ccc;
    padding: 10px;
}
</style>
